import React, { Component } from 'react'
import "./less/login.less"
import { NavBar, InputItem, Button ,Toast} from 'antd-mobile';
import { Link } from "react-router-dom"
import { reqLogin } from '../../http/api';
import { connect } from "react-redux";
import { actions, getUser } from "../../store/modules/login";
import { bindActionCreators } from "redux";
class Login extends Component {
    render() {
        let { user,login:{changeUser,loginAction},history:{push} } = this.props;
        return (

            <div className="nav">

                <NavBar>登录</NavBar>
                <InputItem
                    clear
                    placeholder="请输入账号"
                    onChange={(val) => changeUser("phone",val)}

                >账号</InputItem>
                <InputItem
                    clear
                    placeholder="请输入密码"
                    type="password"
                    onChange={(val) =>changeUser( "password",val)}

                >密码</InputItem>
                <div style={{ width: "33.33%", margin: "10px auto" }}>
                    <Button type="primary" onClick={() => loginAction(push)}>登录</Button>
                    </div>

               {/* <div>{JSON.stringify(user)}</div> */}
                <Link to="/register">没有账号，去注册</Link> 
            </div>
        )
    }
}

const mapStateToProps = (state) => {
    console.log(state);
    return {
      user: getUser(state),
    };
  };
  const mapDispatchToProps = (dispatch) => {
    return {
      login: bindActionCreators(actions, dispatch),
    };
  };
  export default connect(mapStateToProps, mapDispatchToProps)(Login);
